package com.eliza.room.db.dao

import android.content.Context
import androidx.lifecycle.LiveData
import com.eliza.room.model.Student

/**
 * @author ningchuanqi
 * @version V1.0
 */
class StudentRepository {
    private val studentDao: StudentDao

    constructor(context: Context) {
        val database: StuRoomDatabase = StuRoomDatabase.getInstance(context)
        studentDao = database.studentDao
    }

    suspend fun insertStudent(vararg students: Student) {
        studentDao.insertStu(*students as Array<out Student>)
    }


    suspend fun deleteStudent(vararg students: Student) {
        studentDao.deleteStu(*students as Array<out Student>)
    }


    suspend fun updateStudent(vararg students: Student) {
        studentDao.updateStu(*students as Array<out Student>)
    }

    val allStudentsLive: LiveData<List<Student>>
        get() = studentDao.getAllStuList()


}